{include file="public/user_shop_head" /}
{include file="public/href" /}
<link rel="stylesheet" type="text/css" href="__STATIC__/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="__STATIC__/css-wap/style.css">
<style>

</style>
<div class="main">
    <ul class="list">
        <li><span><a href="shop_index?shop_id={:input('shop_id')}">店铺首页</a></span></li>
        <li class="cur"><span><a href="all_goods?shop_id={:input('shop_id')}">全部商品</a></span></li>
        <li><span><a href="sales_promote?shop_id={:input('shop_id')}">促销</a></span></li>
        <li><span><a href="new_list?shop_id={:input('shop_id')}">上新</a></span></li>
    </ul>
<div class="tablist" style="background: #fff;">
    <ul>
        <li {eq name=":input('type',0)" value="0"}class="cur"{/eq}><div><a href="?shop_id={:input('shop_id')}&type=0&search={:input('search','')}"><span>综合</span></a></div></li>
        <li {eq name=":input('type')" value="1"}class="cur"{/eq}><div><a href="?shop_id={:input('shop_id')}&type=1&search={:input('search','')}"><span>销量</span></a></div></li>
        <li {eq name=":input('type')" value="2"}class="cur"{/eq}><div><a href="?shop_id={:input('shop_id')}&type=2&search={:input('search','')}"><span>新品</span></a></div></li>
        <li {if condition="input('type') eq 3 || input('type') eq 4" }class="cur"{/if}><div><a {eq name=":input('type')" value="3"} href="?shop_id={:input('shop_id')}&type=4&search={:input('search','')}" {else/} href="?shop_id={:input('shop_id')}&type=3&search={:input('search','')}" {/eq}><span>价格</span>
        <img {eq name=":input('type',0)" value="3"} src="__STATIC__/img_user/7.png"
             {else/}
        {eq name=":input('type',0)" value='4'}
        src="__STATIC__/img_user/fl-shangtubiao.png"
        {else/}
        src="__STATIC__/img_user/fl-shangxia.png"
        {/eq}
        {/eq}>
        </a></div></li>
    </ul>
    <input type="hidden" value="{:input('shop_id')}" id="shop_id" />
    <input type="hidden" value="{:input('type',0)}" id="type" />
    <div class="down">
        <img src="__STATIC__/img_user/ss-paixu.png" id="sort_img" onclick="sort()">
    </div>
</div>
</div>
<ul class="list_group" id="all_goods" style="margin-top: 40px;">

</ul>
<div class="style_123" style="display:none;margin-top: 40px;">
</div>
{include file="public/shop_footer" /}
</div>
{include file="public/src" /}
<script>
    //搜索
    function search_title(){
        var shop_id = $('#shop_id').val(),
            search = $('#search').val();
        window.location.href = "{:url('mobile/user_category/shop_all_goods')}?shop_id="+shop_id+"&search="+search;
    }
    //页面排序
    function sort(){
        var status = $('#all_goods').css('display');
        if (status == 'none'){
            $('#all_goods').css('display','block');
            $('.style_123').css('display','none');
            $('#sort_img').prop('src','__STATIC__/img_user/ss-paixu.png');
        }else{
            $('#all_goods').css('display','none');
            $('.style_123').css('display','block');
            $('#sort_img').prop('src','__STATIC__/img_user/ss-paixuh.png');
        }
    }
    //未登录跳转到登录
    function jump_login(){
        layer.open({
            content: '您还未登录,请登录'
            ,btn: ['去登录', '取消']
            ,yes: function(index){
                window.location.href="{:url('mobile/user_port/login')}";
                layer.close(index);
            }
        });
    }
    //layer流加载
    layui.use('flow', function() {
        var $ = layui.jquery;
        var flow = layui.flow;
        flow.load({
            elem: '#all_goods' //流加载容器
            ,isAuto:true
            ,isLazyimg:true
            ,done: function(page, next){ //执行下一页的回调
                var lis = [];
                var shop_id = $('#shop_id').val();
                var type = $('#type').val();
                var search = $('#search').val();
                $.ajax({
                    url:"all_goods",
                    dataType:'json',
                    type:'post',
                    data:{'page':page,'shop_id':shop_id,'type':type,'search':search},
                    success:function(t){
                        layui.each(t.data, function(index, item){
                            var url = "{:url('mobile/user_category/goods_details')}?goods_id="+item.id;
                            lis.push('<li><a href="'+url+'"><div class="pic"><img src="/'+item.thumb_img+'" style="height:150px;" onerror=this.src="/static/mobile/img/empty_img.png" >' +
                                    '</div>' +
                                    '<h4 class="title">'+item.title+'</h4><div class="price">&yen;'+item.price+'<span class="sale_num">销量 '+item.sale_number+'</span></div></div></a></li>');
                        });
                        next(lis.join(''), page < t.pages);
                    }
                })
            }
        });
        var flow_list = layui.flow;
        flow_list.load({
            elem: '.style_123' //流加载容器
            ,isAuto:false
            ,isLazyimg:true
            ,done: function(page, next){ //执行下一页的回调
                var lis = [];
                var shop_id = $('#shop_id').val();
                var type = $('#type').val();
                $.ajax({
                    url:"all_goods",
                    dataType:'json',
                    type:'post',
                    data:{'page':page,'shop_id':shop_id,'type':type},
                    success:function(t){
                        layui.each(t.data, function(index, item){
                            var url = "{:url('mobile/user_category/goods_details')}?goods_id="+item.id;
                            lis.push('<div class="content" onclick="jump_goods('+item.id+')"><div class="left"><img src="/'+item.thumb_img+'" onerror=this.src="/static/mobile/img/empty_img.png"></div>' +
                                    '<div class="right" style="height: 90px;"><h4>'+item.title+'</h4>' +
                                    '<div class="price">&yen;'+item.price+'<span style="float:right;font-size:12px;line-height:20px;color:#333;">销量'+item.sale_number+'</span></div>'+
                                    '</div></div></div>');
                        });
                        next(lis.join(''), page < t.pages);
                    }
                })
            }
        });
    });

    //跳转到商品详情
    function jump_goods(id){
        var url = "{:url('mobile/user_category/goods_details')}?goods_id="+id;
        sessionStorage.setItem('goods_url_back',window.location.href);
        window.location.href = url;
    }

    function shop_goods_cate(id) {
        sessionStorage.setItem('shop_cate_back',window.location.href);
        window.location.href="{:url('mobile/user_category/shop_goods_cate')}?shop_id="+id;
    }
</script>
</body>
</html>